package com.roshan.strategy.impl;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.UUID;

import org.springframework.stereotype.Component;

import com.roshan.strategy.UriGenerationStrategy;

@SuppressWarnings("nls")
@Component
public class UriGenerationStrategyImpl implements UriGenerationStrategy {

    private static final String FRAGMENT_SEPERATER = "#";

    @Override
    public <T> URI generateURI(T t) {

        try {
            StringBuilder builder = new StringBuilder();
            builder.append(t.getClass().getSimpleName());
            builder.append(FRAGMENT_SEPERATER);
            builder.append(UUID.randomUUID());
            return new URI(builder.toString().toLowerCase());

        } catch (URISyntaxException e) {
            return null;
        }
    }
}
